<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/11/4
 * Time: 15:25
 */
class SearchAction extends BaseAction{
    function index(){
        $key=Req::get('key');

        $art=new article();
        $ajax=Req::get('ajax');
        if($ajax){
            $page=Req::get('p','intval')?Req::get('p','intval'):1;
            $list=$art->get_list('tid=3&show=20&q='.$key.'&pg='.$page);
            $result=array();
            foreach($list as $v){
                $result[]=array('date'=>date('Y-m-d',$v->startdate),'title'=>$v->title);
            }
            echo json_encode($result);
        }else {
            $list=$art->get_list('tid=3&show=20&q='.$key);
            $this->assign('list',$list);
            $this->assign('ajax',url(array('c'=>'search','ajax'=>1)));
            $this->assign('url', url(array('c' => 'search')));
            $this->assign('key', $key);
            $this->display('search');
        }
        $this->assign('key',$key);
        $this->assign('ajax','?c=search&key='.$key);
    }
}